package com.bhs.mapper;

import com.bhs.pojo.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface UserMapper {
    // 注册用户
    @Insert("insert into user values (null,#{username},#{password},null,null,#{phone})")
    void register(User user);

    @Select("select id,username,password from user where username=#{username}")
    User doSelectUserByUsername(String username);

    @Select("SELECT DISTINCT m.permission " +
            "FROM user_roles ur " +
            "JOIN role_permission rm ON ur.role_id=rm.role_id " +
            "JOIN permission m ON rm.permission_id=m.id " +
            "WHERE ur.user_id=#{userId}")
    List<String> selectUserPermissions(Long userId);
}
